﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Pigs.Weapons
{
    public class Bomb : pigs.DynamicObject
    {
        // Position of the bullet relative to the upper left side of the screen
        public Vector2 Direction;

        //angle that it's fired at
        public float angle;

        // Determines how fast the projectile moves
        float projectileMoveSpeed;

        //is the bullet reflected from a steel pig
        public bool reflected;


        public int timer;

        /// <summary>
        /// create the bullet
        /// </summary>
        /// <param name="texture">texture to use for the bullet</param>
        /// <param name="position">where to draw the bullet</param>
        public Bomb(Texture2D texture, Vector2 position)
            : base(texture, position)
        {
            timer = 50;
        }

        /// <summary>
        /// initialize the bullet
        /// </summary>
        /// <param name="direction">vector of the position it's going to</param>
        public void Initialize(Vector2 direction)
        {
            Direction = direction;

            //calculate the angle from the direction it's going
            angle = (float)(Math.Atan2(direction.Y, direction.X));
            damage = 1;

            projectileMoveSpeed = 13f;
            reflected = false;

            rectangle = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);
        }

        /// <summary>
        /// update the bullets position
        /// </summary>
        public void Update()
        {
            timer--;

            // Projectiles always move to the right
            position += projectileMoveSpeed * Direction;
            rectangle.Offset((int)(projectileMoveSpeed * Direction.X), (int)(projectileMoveSpeed * Direction.Y));
            rectangle = new Rectangle((int)position.X, (int)position.Y, rectangle.Width, rectangle.Height);
        }

        /// <summary>
        /// draw the bullet
        /// </summary>
        /// <param name="spriteBatch">the spritebatch to draw the bullet in</param>
        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, position, null, Color.White, angle, new Vector2(texture.Width / 2, texture.Height / 2), 1f, SpriteEffects.None, 0f);
        }
    }
}
